package com.mbl.base.modular.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.mbl.base.modular.mall.entity.Cart;
import com.mbl.base.modular.mall.mapper.CartMapper;
import com.mbl.base.modular.mall.service.ICartService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 购物车商品表 服务实现类
 * </p>
 *
 * @author lwj
 * @since 2020-03-22
 */
@Service
public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements ICartService {

    @Override
    public List<Cart> getByUidAndChecked(Long userId) {
        return query().eq("user_id", userId).eq("checked", true).list();
    }

    @Override
    public void clearGoods(Long userId) {
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("user_id",userId);
        updateWrapper.eq("checked",true);
        updateWrapper.set("flag",true);
        update(updateWrapper);
    }

    @Override
    public Cart queryExist(Long goodsId, Long productId, Long userId) {
        return query().eq("goods_id",goodsId).eq("product_id",productId).eq("user_id",userId).one();
    }

    @Override
    public List<Cart> queryByUid(Long userId) {
        return query().eq("user_id",userId).list();
    }
}
